package ru.ifmo.ipimenov.ewf_svn.standalone.dao.impl;

import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import ru.ifmo.ipimenov.ewf_svn.standalone.dao.CategoryDao;
import ru.ifmo.ipimenov.ewf_svn.standalone.model.db.Category;
import ru.ifmo.ipimenov.ewf_svn.standalone.util.HibernateUtil;

/**
 * @author: Ilya Pimenov
 * Scartel Starlab company
 */
public class CategoryDaoHibernate implements CategoryDao {
    public Category load(Integer id) {
        Session s = HibernateUtil.getSessionFactory().getCurrentSession();
        s.beginTransaction();

        Category c = (Category) s.createCriteria(Category.class).add(Restrictions.eq("id", id)).uniqueResult();
        s.getTransaction().commit();

        return c;

    }

    public void save(Category c) {
        Session s = HibernateUtil.getSessionFactory().getCurrentSession();
        s.beginTransaction();

        s.save(c);

        s.getTransaction().commit();
    }
}
